#include "AETaskManager.hpp"
#include "AELogManager.hpp"

template<> arete::thread::AETaskManager* Ogre::Singleton<arete::thread::AETaskManager>::msSingleton = 0;

using namespace arete::io;

BEGIN_ARETE_NAMESPACE(thread)

	AETaskManager::AETaskManager(void) :
	m_stop(false)
{
}

AETaskManager::~AETaskManager(void)
{
	m_stop = true;
	m_condition.notify_all();

	for(size_t i = 0; i < m_workers.size(); ++i)
	{
		m_workers[i].join();
	}
}

void AETaskManager::initialize(const size_t& threads)
{
	AELogManager::log(ELL_NONE,"*****************************************");
	AELogManager::log(ELL_NONE,"*** --- Initializing Task Manager --- ***");
	AELogManager::log(ELL_NONE,"*****************************************");

	m_stop = false;

	for(size_t i = 0; i < threads; ++i)
	{
		m_workers.push_back(std::thread(AEWorker(*this)));
	}
}

END_ARETE_NAMESPACE